#ifndef PAGE_H
#define PAGE_H

#include "inc.h"
#include "slot.h"

#define PAGE_SIZE 2048
#define PAGE_LOCATE(mem, offset)    ((char *) mem + offset)
#define PAGE_SET(field, value)      (*(field) = value)
#define PAGE_GET(field)             (*(field))
#define PAGE_RECORD_NUM(page)       ((slot_t *) (page)->lower - (page)->slot)

enum USED_FLAG {
    UNUSED = 0,     /* relative to the init operation in allocPages() */
    USED = 1
};

/*
 * struct Page store the pointers that
 * point to the relative region in the 
 * real page  
 * 
 * so get the real data from the memory 
 * that struct page point to
 * 
 * do not get data directly from such pointer
 * 
 * assume the struct page as a header of the
 * real page in memory
 */
typedef struct Page {
    void *mem;          /* point at the really allocated memory */
    uint8_t *type;      /* belong to waht table */
    uint8_t *is_used;
    slot_t *slot;
    char *lower;
    char *upper;
    void *end;
} page_t;

void printPageLayout(page_t *page);

#endif  /* PAGE_H */